<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
    	$this->login_verify();
    	$banner=M('banner');
    	$bannerlist=$banner->select();
    	$this->assign("bannerlist",$bannerlist);
    	$project=M('project');
    	$type=isset($_GET['type'])?$_GET['type']:1;
    	$projectlist=$project->where("type=".$type)->select();
    	$this->assign("type",$type);
    	$this->assign("projectlist",$projectlist);
        $this->display();
    }
    public function ajaxGetProject(){
    	$type=I('post.type');
    	$project=M('project');
    	$projectlist=$project->where("type=".$type)->select();
    	$this->ajaxReturn($projectlist);
    }

  	public function bannerset(){
	    $upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     2097152 ;// 设置附件上传大小
	    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	    $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
	    $upload->subName  =      'banner';
	    // 上传单个文件 
	    $info   =   $upload->uploadOne($_FILES['banner']);
	    if(!$info) {// 上传错误提示错误信息
	        $this->error($upload->getError());
	    }else{// 上传成功 获取上传文件信息
	    	$banner=M("banner");
	    	$data['imgurl']='Uploads/'.$info['savepath'].$info['savename'];
	    	if($banner->data($data)->add()){
	    		$this->success("上传成功",U("Index/index"));
	    	}else{
	    		$this->error("上传失败");
	    	}
	    }
    }

    public function bannerDel(){
    	$id=I('get.id');
    	$banner=M('banner');
    	if($banner->where('id='.$id)->delete()){
	        	$this->success("删除成功",U('Index/index'));
    	}else{
	        	$this->error("删除失败");
    	}
	}
	/*项目展示*/
	public function projectshow(){
		$project=M("project");
		$data['type']=$_POST['type'];
		$upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     2097152 ;// 设置附件上传大小
	    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	    $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
	    $upload->subName  =      'project';
	    // 上传单个文件 
	    $info   =   $upload->uploadOne($_FILES['project']);
	    if(!$info) {// 上传错误提示错误信息
	        $this->error($upload->getError());
	    }else{// 上传成功 获取上传文件信息
	    	$project=M("project");
	    	$data['imgurl']='Uploads/'.$info['savepath'].$info['savename'];
	    	if($project->data($data)->add()){
	    		$this->success("上传成功",U("Index/index",array("type"=>$data['type'])));
	    	}else{
	    		$this->error("上传失败");
	    	}
	    }
    	
	}
	public function projectDel(){
    	$id=I('get.id');
    	$project=M('project');
    	$data=$project->where('id='.$id)->select();	
    	if($project->where('id='.$id)->delete()){
	        	$this->success("删除成功",U('Index/index',array("type"=>$data[0]['type'])));
    	}else{
	        	$this->error("删除失败");
    	}
	}
}